package com.shrct.businessprocess.purchase.impl;

import com.shrct.businessprocess.product.RCProductSpecification;
import com.shrct.businessprocess.product.impl.RCProductSpecificationImpl;
import com.shrct.businessprocess.project.RCProjectMoney;
import com.shrct.businessprocess.purchase.RCProductPurchaseItem;
import com.shrct.businessprocess.purchase.proxy.RCProductPurchaseItemProxy;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("RCPRODUCTPURCHASEITEM_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rcproductpurchaseitem")
public class RCProductPurchaseItemImpl extends BaseModelObject implements RCProductPurchaseItem {
  public RCProductPurchaseItemImpl() {
    super();
  }
  
  @JoinColumn(name = "productSpec_id")
  @ManyToOne(targetEntity = RCProductSpecificationImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCProductSpecification productSpec;
  
  public RCProductSpecification getProductSpec() {
    return this.productSpec;
  }
  
  public RCProductPurchaseItem setProductSpec(final RCProductSpecification productSpec) {
    this.productSpec = productSpec;
    return this;			
    
  }
  
  private Integer quantity;
  
  public Integer getQuantity() {
    return this.quantity;
  }
  
  public RCProductPurchaseItem setQuantity(final Integer quantity) {
    this.quantity = quantity;
    return this;			
    
  }
  
  @Embedded
  @AttributeOverrides(value = { @AttributeOverride(name = "amount", column = @Column(name = "amount_amount") ), @AttributeOverride(name = "workaround", column = @Column(name = "amount_workaround") ) } )
  @AssociationOverrides(value = @AssociationOverride(name = "exchange", joinColumns = @JoinColumn(name = "amount_exchange") ) )
  private RCProjectMoney amount = com.shrct.businessprocess.project.RCProjectMoney.create();
  
  public RCProjectMoney getAmount() {
    return this.amount;
  }
  
  public RCProductPurchaseItem setAmount(final RCProjectMoney amount) {
    this.amount = amount;
    return this;			
    
  }
  
  private Integer requestQuantity;
  
  public Integer getRequestQuantity() {
    return this.requestQuantity;
  }
  
  public RCProductPurchaseItem setRequestQuantity(final Integer requestQuantity) {
    this.requestQuantity = requestQuantity;
    return this;			
    
  }
  
  private Integer orderQuantity;
  
  public Integer getOrderQuantity() {
    return this.orderQuantity;
  }
  
  public RCProductPurchaseItem setOrderQuantity(final Integer orderQuantity) {
    this.orderQuantity = orderQuantity;
    return this;			
    
  }
  
  private Integer acceptQuantity;
  
  public Integer getAcceptQuantity() {
    return this.acceptQuantity;
  }
  
  public RCProductPurchaseItem setAcceptQuantity(final Integer acceptQuantity) {
    this.acceptQuantity = acceptQuantity;
    return this;			
    
  }
  
  private Integer deliveredQuantity;
  
  public Integer getDeliveredQuantity() {
    return this.deliveredQuantity;
  }
  
  public RCProductPurchaseItem setDeliveredQuantity(final Integer deliveredQuantity) {
    this.deliveredQuantity = deliveredQuantity;
    return this;			
    
  }
  
  /**
   * 已发货数量
   */
  public void add(final Integer quantity, final RCProjectMoney amount) {
    int _plus = ((quantity).intValue() + (this.quantity).intValue());
    this.quantity = Integer.valueOf(_plus);
  }
  
  public String getEntityName() {
    String _name = this.productSpec.getName();
    return _name;
  }
  
  public static RCProductPurchaseItem create(final IObjectFactory objectFactory) {
    com.shrct.businessprocess.purchase.RCProductPurchaseItem rCProductPurchaseItem = new com.shrct.businessprocess.purchase.impl.RCProductPurchaseItemImpl(
    );
    objectFactory.create(rCProductPurchaseItem);
    return rCProductPurchaseItem;			
    
  }
  
  public static RCProductPurchaseItem createRCProductPurchaseItemImpl(final IObjectFactory objectFactory, final Procedure1<RCProductPurchaseItem> init) {
    com.shrct.businessprocess.purchase.RCProductPurchaseItem rCProductPurchaseItem = new com.shrct.businessprocess.purchase.impl.RCProductPurchaseItemImpl(
    );
    objectFactory.create(rCProductPurchaseItem);
    init.apply(rCProductPurchaseItem);
    
    return rCProductPurchaseItem;			
    
  }
  
  public RCProductPurchaseItemProxy toProxy() {
    com.shrct.businessprocess.purchase.proxy.RCProductPurchaseItemProxy proxy = new com.shrct.businessprocess.purchase.proxy.RCProductPurchaseItemProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
